//window.onload = function() {
//	var stocks = [];
//	var content = document.getElementById("demo");	
//	submitForm();
//	//setInterval("AJAX_JSON_Req()", 10000);
//	setInterval("submitForm()", 2000);
//}

function AJAX_JSON_Req(req, page)
{
	employe = JSON.parse(req);
	display(employe, page);

}
function json(){
	var xmlhttp = new XMLHttpRequest();
	xmlhttp.open("GET", './convertdb.php', true);
	var json = xmlhttp.responseText;
	document.getElementById("demo").innerHTML = json;
	xmlhttp.send();
}
function createInstance()
{
	var req = null;
	if(window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("XHR not created");
			}
		}
	}
	return req;
}
function storing(data, element)
{
	element.innerHTML = data;
}
function submitForm(page)
{ 
	var req = createInstance();
	req.onreadystatechange = function()
	{ 
		if(req.readyState == 4)
		{
			if(req.status == 200)
			{
//				storing(req.responseText, element);
				AJAX_JSON_Req(req.responseText, page);

			}	
			else	
			{
				document.ajax.dyn.value="Error: returned status code " + req.status + " " + req.statusText;
			}	
		} 
	}; 
	req.open("GET", "./convertdb.php", true); 
	req.send(null); 
} 
function display(employe, page){
	var out = "";
	var i;
	alert(page);
	
	for(i = 0; i < employe.length; i++) {
		if(employe[i].TITRE==page){
			
			out = employe[i].CORPS;
		}
		

	}

	document.getElementById("features").innerHTML = out;

}
function add(){
	var msg=document.getElementById('msg').value;
	var nom=document.getElementById('cache').value;
	$.post(
			'send_msg.php',
			{
				utilisateur: nom,
				msg : msg
			}, 
			function(data){
				/*

	    	    if(data==success){
	    		   alert('message envoyÃ©');
	    	   	}
	    	   else{
	    		   alert('a problem has occured');
	    	   }
				 */ 
			},
			'text'
	);
	document.getElementById('msg').value = "";

}